/**
 * 功能描述
 */
define(function (require, exports, module) {
    //引入视图基类
    var ELView = require("elview");
    var aw = require("ajaxwrapper");
    //assets
    var template = require("./assets/tpl/checkoutsettlement_main.tpl");
    require("./assets/css/checkoutsettlement_main.css");

    //business

    //component
    var cSettlementSubnav = require("./component/checkOutSettlementSubnavComp");
    var cSettlementGrid = require("./component/checkOutSettlementGridComp"); 
    var cSettlementEditGridComp = require("./component/checkOutSettlementEditGridComp");
    var cSettlementForm = require("./component/checkOutSettlementFormComp");
    var cSettlementEndGrid = require("./component/checkOutSettlementEndGrid");
    var cSettlementDetailForm = require("./component/checkOutSettlementDetailForm");
    var settleForm = require("./component/settleForm");
    var settleEditGridOne = require("./component/settleEditGridOne");
    var onCreditForm = require("./component/onCreditForm");
    var settleEditGridTwo = require("./component/settleEditGridTwo");
    //constant
    var fetchProperties = require("./constant/fetchProperties");
    //handler
    var handler = require("./handler/checkOutSettlementHandler");
    var detailEvents = require("./handler/detailEvents");

    //store
    var store = require("./store/checkOutSettle");

    var App = ELView.extend({
        attrs: {
            template: template
        },
        events: {
        	"blur .J-detailForm :input" : function(e){
        		handler.detailForm.settleEvents(e);
        	}
        },
        handler: handler,
        detailHandler:detailEvents,
        store: store,
        detail: false,
        initComponent: function (params, widget) {
        	cSettlementSubnav.initComponent(params, widget);
        	cSettlementGrid.initComponent(params, widget);
        	cSettlementEditGridComp.initComponent(params, widget);
        	cSettlementForm.initComponent(params, widget);
        	cSettlementEndGrid.initComponent(params, widget);
        	cSettlementDetailForm.initComponent(params, widget);
        	settleEditGridOne.initComponent(params, widget);
        	settleEditGridTwo.initComponent(params, widget);
        	settleForm.initComponent(params, widget);
//        	onCreditForm.initComponent(params, widget);
        },
        afterInitComponent: function (params, widget) {
    		aw.ajax({
				url:"api/baseprice/getprice",
				dataType:"json",
				success:function(datas){
					widget.set("basePrice",datas);
					widget.get("grid").refresh();
				}
			})
            		
            if(params && params.type == "roomstatewhole"){
            	aw.ajax({
					url:"api/checkinimplement/querycheckbyid",
					dataType:"json",
					data:{
						pkCIImplement:params.pkCIImplement,
						fetchProperties: fetchProperties.grid
					},
					success:function(data){
						widget.handler.grid.handlerSettleClick(widget,data);
					}
    			})
        	} 
        }
    });
    module.exports = App;
});
